package com.heima.controller;


import com.heima.pojo.TbSkuClass;
import com.heima.pojo.vo.PageResponse;
import com.heima.service.ITbSkuClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品类别表 前端控制器
 * </p>
 *
 * @author nan
 * @since 2024-06-04
 */
@RestController
@RequestMapping("/api/vm-service/skuClass")
@Api(tags = "商品管理")
public class TbSkuClassController {

    @Autowired
    private ITbSkuClassService skuClassService;

    @PostMapping
    @ApiOperation("新增分类")
    public Boolean addSkuClass(@RequestBody TbSkuClass skuClass) {

        return skuClassService.save(skuClass);
    }

    @GetMapping("/search")
    @ApiOperation("分类搜索")
    public PageResponse<TbSkuClass> getByPage(@RequestParam Integer pageIndex,
                                              @RequestParam Integer pageSize,
                                              @RequestParam(required = false) String className) {

        return skuClassService.getByPage(pageIndex, pageSize, className);
    }

    @GetMapping("/{id}")
    @ApiOperation("获取分类基本信息")
    public TbSkuClass getById(@PathVariable String id) {
        return skuClassService.getById(id);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改分类")
    public Boolean update(@PathVariable String id, @RequestBody TbSkuClass tbSkuClass) {
        tbSkuClass.setClassId(Integer.parseInt(id));
        return skuClassService.updateById(tbSkuClass);
    }

    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable String id) {
        skuClassService.removeById(id);
    }
}
